import re

ddl = """
CREATE TABLE `orders_normal_orders` (
  `order_id` bigint(20) NOT NULL COMMENT '订单号',
  `batch_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '拆单批次号',
  `supplier_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '供应商id',
  `title` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '订单标题',
  `company_id` bigint(20) NOT NULL COMMENT '公司id',
  `freight_type` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'cash' COMMENT '运费类型-用于积分商城 cash:现金 point:积分',
  `update_time` int(11) DEFAULT NULL COMMENT '订单更新时间',
  `fee_type` varchar(5) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'CNY' COMMENT '货币类型',
  `fee_rate` double NOT NULL DEFAULT '1' COMMENT '货币汇率',
  `fee_symbol` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '￥' COMMENT '货币符号',
  PRIMARY KEY (`order_id`),
  KEY `idx_order_class` (`order_class`),
  KEY `ix_receiver_mobile_create_time` (`receiver_mobile`,`create_time`) USING BTREE,
  KEY `ix_store_id` (`store_id`),
  KEY `ix_pickup_point_id` (`pickup_point_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='实体订单表';
"""

# 定义正则表达式模式
pattern_fields = r"^\s+([^`]+)` ([^.\s(]+)(?:[^']+)?(?:\s+COMMENT\s+'([^']+)'(?:[^']+))?(?:\s+DEFAULT\s+'([^']+)'(?:[^']+))?,"

# 使用正则表达式匹配字段行
matches = re.findall(pattern_fields, ddl, re.MULTILINE)
print(matches)

# 提取匹配结果
columns = []
for match in matches:
    field = match[0]
    data_type = match[1]
    comment = match[2] if match[2] else ''
    default_value = match[3] if match[3] else ''
    column = {
        'field': field,
        'data_type': data_type,
        'comment': comment,
        'default_value': default_value
    }
    columns.append(column)
# 打印匹配结果
for column in columns:
    print(column)